<template>
  <el-dialog
    title="弹出"
    :visible="showempDialog"
    @close="guanbi"
  >
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="i in list" :key="i.id" :label="i.id">{{ i.name }}</el-checkbox>

    </el-checkbox-group>
    <el-button @click="tijiao">提交</el-button>
  </el-dialog>
</template>

<script>
import { assignRoles, enabled, enabledid } from '@/api/user'
export default {
  props: {
    showempDialog: {
      type: Boolean,
      required: true
    },
    cruid: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  async created() {
    const res = await enabled()
    console.log(res)
    this.list = res.data
  },
  methods: {
    guanbi() {
      this.$emit('update:showempDialog', false)
    },
    async qingqiu() {
      const res = await enabledid(this.cruid)
      console.log(res)
      this.roleIds = res.data.roleIds
    },
    async tijiao() {
      const res = await assignRoles({ roleIds: this.roleIds, id: this.cruid })
      this.$message.success('保存成功')
      this.guanbi()
      console.log(res)
    }
  }
}
</script>

<style>

</style>
